const Sequelize = require('sequelize');
const Op = Sequelize.Op;
module.exports = (db, DataTypes) => {
  // store hours or weekday
  return db.define('EquipmentAttribute', {
    value: DataTypes.FLOAT,
    active: {
      type: DataTypes.BOOLEAN,
      defaultValue: true,
    }
  }, {
    defaultScope: {
      where: {
        active: true,
      }
    },
    scopes: {
      all: {
        where: {
          [Op.or] : [{
            active: false,
          },{
            active: true,
          }]
        }
      }
    },
    associate(models) {
      models.EquipmentAttribute.belongsTo(models.Equipment, { foreignKey: 'EquipmentId' });
      models.EquipmentAttribute.hasMany(models.InspectionRecord);
    }
  })
};
